package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;





import entity.Order;

import net.sf.json.JSONArray;
import service.OrderService;

/**
 * Servlet implementation class WaitSendServlet
 */
@WebServlet("/AllOrderServlet")
public class AllOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AllOrderServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int id=1;
		request.getSession().setAttribute("id", id);
		String waitPay = request.getParameter("waitPay"); //获取POST传递过来的值
		OrderService orderService =new OrderService();
		List<Order> ordersByUidStatus = orderService.getOrdersByUidStatus(id, waitPay); //根据用户Id和订单状态查询符合的订单返回订单集合
		//将json所需的包放到lib里面,将list转换为json
        JSONArray json=JSONArray.fromObject(ordersByUidStatus);
        //响应前台页面
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/json");
        PrintWriter out=response.getWriter();
        out.println(json);//打印json，为了前台页面获取
        out.flush();//刷新流
        out.close();//关闭流
		
		}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
